<template>
  <el-dialog title="确认发布" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">

    <el-descriptions title="" :column="1" :label-style="{ width: '150px' }">
      <el-descriptions-item label="活动开始时间">{{ buzTask.startTime || '' }}</el-descriptions-item>
      <el-descriptions-item label="活动结束时间">{{ buzTask.endTime || '' }}</el-descriptions-item>
      <el-descriptions-item label="活动名称">{{ buzTask.title || '' }}</el-descriptions-item>
      <!--<el-descriptions-item label="活动派奖方式">无需派奖</el-descriptions-item>-->
    </el-descriptions>

    <div style="padding-top: 20px; font-size: 14px; color: #898989;">发布后，未发布时的测试数据会被清空</div>

    <el-divider />

    <!--活动用途：
    <el-select v-model="activeUse" placeholder="请选择活动用途">
      <el-option
        v-for="item in activeUseOptions"
        :key="item.value"
        :label="item.label"
        :value="item.value"/>
    </el-select>-->

    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="onConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getTaskData, publishTask } from '@/api/system/buzTask'

export default {
  data() {
    return {
      buzTask: {},
      dialogVisible: false,
      activeUse: '',
      activeUseOptions: [
        { label: '请选择', value: '0' },
        { label: '门店引流', value: '1' },
        { label: '现场活动', value: '2' },
        { label: '公众号吸粉', value: '3' },
        { label: '电商引流', value: '4' },
        { label: '品牌传播', value: '5' },
        { label: '其他', value: '6' }
      ]
    }
  },
  methods: {
    open(id) {
      console.log(id, 'id')
      // this.dialogVisible = true
      this.getDetail(id)
    },
    handleClose() {
      this.dialogVisible = false
      this.buzTask = {}
    },
    getDetail(id) {
      getTaskData(id).then(res => {
        if (res.code === 200) {
          this.buzTask = res.data.buzTask
          this.dialogVisible = true
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          })
        }
      })
    },
    onConfirm() {
      // TODO 提交数据
      console.log('提交数据')
      publishTask(this.buzTask.id).then(e => {
        if (e.code === 200) {
          this.$message({
            type: 'success',
            message: '发布成功'
          })
          this.dialogVisible = false
          this.$emit('success', this.buzTask.id)
        } else {
          this.$message({
            type: 'error',
            message: e.msg
          })
        }
      })
    }
  }
}
</script>

<style scoped>
 .el-divider--horizontal{
    background: 0 0;
    border-top: 1px dashed #DCDFE6;
 }
</style>
